define(['app','echarts','echartsGL'],function(app,echarts){return {module: function($scope, $http, eventBusService, httpService, params, configService) {
	//获取教师学校总数
	$scope.all = function(fk_dictionary_school_type,fk_unit) {
		httpService.post(app.urls.unit_selectCountAtCenter,{"fk_dictionary_school_type":fk_dictionary_school_type,"fk_unit":fk_unit}, function (data) {
	        if ("0000" === data.code) {
	            $scope.form.teacher = data.data.js;
	        } else {
	            alert(data.msg);
	        }
	    });
	}
	//条件筛选-学段
	httpService.post(app.urls.dictionary_selectByRule,{fk_rule:"182c0cbc8924435ab6773779d9f2f48f"},function(data){
		if("0000" === data.code){
			 $scope.stageList = data.data;
		}else{
			alert(data.msg);
		}
	});
    //条件筛选-学校
    $scope.findUnit = function(fk_dictionary_school_type){
        httpService.post(app.urls.schoolanalysis_selectUnitConditon, {"fk_dictionary_school_type":fk_dictionary_school_type}, function (data) {
            if ("0000" === data.code) {
                $scope.schoolList = data.data;
            } else {
                alert(data.msg);
            }
        });
    }
    $scope.findUnit();
    $scope.findStage = function(fk_dictionary_school_type) {
    	$scope.findUnit(fk_dictionary_school_type);
    	$scope.find(fk_dictionary_school_type);
    }
	$scope.find = function(fk_dictionary_school_type,fk_unit) {
		$scope.all(fk_dictionary_school_type,fk_unit);
		//教师-性别
	    httpService.post(app.urls.teacheranalysis_selectSex, {"fk_dictionary_school_type":fk_dictionary_school_type,"fk_unit":fk_unit}, function (data) {
	        if ("0000" === data.code) {
	            $scope.sex = data.data;
	            $scope.sex.name = [];
	            $scope.sex.value = [];
	            for (var i = 0; i < $scope.sex.length; i++) {
	                $scope.sex.name.push($scope.sex[i].name);
	                $scope.sex.value.push($scope.sex[i].value);
	            }
	            $scope.echartsInitSex();
	        } else {
	            alert(data.msg);
	        }
	    });
	    $scope.echartsInitSex = function () {
	        // 基于准备好的dom，初始化echarts图表
	        var myChart = echarts.init(document.getElementById("mobile_analysis_teacher_sex"));
	        option = {

	        	    tooltip: {
	        	        trigger: 'item',
	        	        formatter: "{a} <br/>{b}: {c} ({d}%)",

	        	    },
	        	    legend: {
	        	        
	        	        orient: 'vertical',
	        	        x: 'right',
	        	       itemWidth: 14,
	        	        itemHeight: 14,
	        	        align: 'left',
	        	    
	        	        data:$scope.sex.name,
	        	                textStyle: {
	        	            color: '#000'
	        	        }
	        	    },
	        	    series: [
	        	        {
	        	            name:'性别占比',
	        	            type:'pie',
	        	            radius: ['0', '55%'],
	        	            color: ['#ffd7a1', '#a1d2ff', '#e0a1ff'],
	        	            label: {
	        	                normal: {
	        	                    formatter: '{b}\n{d}%'
	        	                },
	        	          
	        	            },
	        	            data:$scope.sex
	        	        }
	        	    ]
	        	};
	        myChart.setOption(option);
	    }
	    //教师-年龄
	    httpService.post(app.urls.teacheranalysis_selectAge, {"fk_dictionary_school_type":fk_dictionary_school_type,"fk_unit":fk_unit}, function (data) {
	        if ("0000" === data.code) {
	            $scope.age = data.data;
	            $scope.age.name = [];
	            $scope.age.value = [];
	            for (var i = 0; i < $scope.age.length; i++) {
	                $scope.age.name.push($scope.age[i].name);
	                $scope.age.value.push($scope.age[i].value);
	            }
	            $scope.echartsInitAge();
	        } else {
	            alert(data.msg);
	        }
	    });
	    $scope.echartsInitAge = function () {
	        // 基于准备好的dom，初始化echarts图表
	        var myChart = echarts.init(document.getElementById("mobile_analysis_teacher_age"));
	        option = {
	            backgroundColor: '#fff',
	            grid: {
	                top: '15%',
	                right: '10%',
	                left: '10%',
	                bottom: '12%'
	            },
	            xAxis: [{
	                type: 'category',
	                color: '#59588D',
	                data: $scope.age.name,
	                axisLabel: {
	                    show: true,
	                    color: '#A0A4AA',
	                    interval: 0,
	                    rotate: '25',
	                    fontSize: 12,
	                },
	                axisLine: {
	                    lineStyle: {
	                        color: '#d2d2d2',
	                    }
	                },
	                axisTick: {
	                    show: false
	                },
	            }],
	            yAxis: [{
	                min: 0,
	                interval: 500,
	                type: 'value',
	                axisLine: {
	                    lineStyle: {
	                        color: 'rgba(107,107,107,0.37)',
	                    }
	                },
	                axisTick: {
	                    show: false
	                },
	                splitLine: {
	                    lineStyle: {
	                        color: 'rgba(131,101,101,0.2)',
	                        type: 'dashed',
	                    }
	                }
	            }],
	            series: [{
	                type: 'bar',
	                data: $scope.age.value,
	                barWidth: '12px',
	                itemStyle: {
	                    normal: {
	                        color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [{
	                            offset: 0,
	                            color: '#FF9A22' // 0% 处的颜色
	                        }, {
	                            offset: 1,
	                            color: '#FFD56E' // 100% 处的颜色
	                        }], false),
	                        barBorderRadius: [30, 30, 0, 0],
	                    }
	                },
	                label: {
	                    show: true,
	                    fontSize: 12,
	                    fontWeight: 'bold',
	                    position: 'top',
	                    color: 'blue',
	                }
	            }]
	        };
	        myChart.setOption(option);
	    }
	    //教师-距离退休
	    httpService.post(app.urls.teacheranalysis_selectRetire, {"fk_dictionary_school_type":fk_dictionary_school_type,"fk_unit":fk_unit}, function (data) {
	        if ("0000" === data.code) {
	            $scope.retire = data.data;
	            $scope.retire.name = [];
	            $scope.retire.value = [];
	            for (var i = 0; i < $scope.retire.length; i++) {
	                $scope.retire.name.push($scope.retire[i].name);
	                $scope.retire.value.push($scope.retire[i].value);
	            }
	            $scope.echartsInitRetrie();
	        } else {
	            alert(data.msg);
	        }
	    });
	    $scope.echartsInitRetrie = function () {
	        // 基于准备好的dom，初始化echarts图表
	        var myChart = echarts.init(document.getElementById("mobile_analysis_teacher_retire"));
	        option = {
	        	    xAxis: {
	        	        type: 'category',
	        	        data:$scope.retire.name,
	        	        axisLine:{       
	        	          "show":false
	        	          
	        	        },
	        	        axisLabel: {
		                    show: true,
		                    color: '#A0A4AA',
		                    interval: 0,
		                    rotate: '25'
		                },
	        	        axisTick:{       
	        	          "show":false
	        	        },
	        	        splitLine: {     
	        	          "show": false
	        	        }
	        	    },
	        	    yAxis: {
	        	        type: 'value',
	        	        show:false,
	        	          axisLine:{       //y轴
	        	          "show":false

	        	        },
	        	        axisTick:{       //y轴刻度线
	        	          "show":false
	        	        },
	        	        splitLine: {     //网格线
	        	          "show": false
	        	        }
	        	    },
	        	    series: [{
	        	        data: $scope.retire.value,
	        	        type: 'bar',
	        	        itemStyle:{
	        	            normal:{
	        	                label:{
	        	                  formatter: "{c}",
	        	                  show: true,
	        	                  position: "top",
	        	                  textStyle: {
	        	                    fontWeight: "bolder",
	        	                    fontSize: "12",
	        	                },
	        	                },
	        	                 //每根柱子颜色设置
	        	                color: function(params) {
	        	                    let colorList = [
	        	                        "#C1232B",
	        	                        "#B5C334",
	        	                        "#FCCE10",
	        	                        "#E87B10",
	        	                        "#277C7B",
	        	                        "#FE8463",
	        	                        "#9e78d1",
	        	                        "#e960b5",
	        	                        "#78d1c4",
	        	                        "#acc65c",
	        	                        "#73c664",
	        	                        "#5a6baa",
	        	                        "#FE8463",
	        	                        "#e7bc82",
	        	                        "#7dcee9",
	        	                        "#ff8c5c",
	        	                    ];
	        	                    return colorList[params.dataIndex];
	        	                }
	        	            }
	        	        }
	        	    }]
	        	};
	        myChart.setOption(option);
	    }
	    //教师-教龄
	    httpService.post(app.urls.teacheranalysis_selectYear, {"fk_dictionary_school_type":fk_dictionary_school_type,"fk_unit":fk_unit}, function (data) {
	        if ("0000" === data.code) {
	            $scope.year = data.data;
	            $scope.year.name = [];
	            $scope.year.value = [];
	            for (var i = 0; i < $scope.year.length; i++) {
	                $scope.year.name.push($scope.year[i].name);
	                $scope.year.value.push($scope.year[i].value);
	            }
	            $scope.echartsInitYear();
	        } else {
	            alert(data.msg);
	        }
	    });
	    $scope.echartsInitYear = function () {
	        // 基于准备好的dom，初始化echarts图表
	        var myChart = echarts.init(document.getElementById("mobile_analysis_teacher_year"));
	        option = {
	            backgroundColor: '#fff',
	            grid: {
	                top: '15%',
	                right: '10%',
	                left: '10%',
	                bottom: '12%'
	            },
	            xAxis: [{
	                type: 'category',
	                color: '#59588D',
	                data: $scope.year.name,
	                axisLabel: {
	                    show: true,
	                    color: '#A0A4AA',
	                    interval: 0,
	                    rotate: '25',
	                    fontSize: 12,
	                },
	                axisLine: {
	                    lineStyle: {
	                        color: '#d2d2d2',
	                    }
	                },
	                axisTick: {
	                    show: false
	                },
	            }],
	            yAxis: [{
	                min: 0,
	                interval: 500,
	                type: 'value',
	                axisLine: {
	                    lineStyle: {
	                        color: 'rgba(107,107,107,0.37)',
	                    }
	                },
	                axisTick: {
	                    show: false
	                },
	                splitLine: {
	                    lineStyle: {
	                        color: 'rgba(131,101,101,0.2)',
	                        type: 'dashed',
	                    }
	                }
	            }],
	            series: [{
	                type: 'bar',
	                data: $scope.year.value,
	                barWidth: '12px',
	                itemStyle: {
	                    normal: {
	                        color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [{
	                            offset: 0,
	                            color: '#a757ffcf' // 0% 处的颜色
	                        }, {
	                            offset: 1,
	                            color: '#ef88e2' // 100% 处的颜色
	                        }], false),
	                        barBorderRadius: [30, 30, 0, 0],
	                    }
	                },
	                label: {
	                    show: true,
	                    fontSize: 12,
	                    fontWeight: 'bold',
	                    position: 'top',
	                    color: 'blue',
	                }
	            }]
	        };
	        myChart.setOption(option);
	    }
	    //教师-职称统计
	    httpService.post(app.urls.teacheranalysis_selectVocation, {"fk_dictionary_school_type":fk_dictionary_school_type,"fk_unit":fk_unit}, function (data) {
	        if ("0000" === data.code) {
	            $scope.vocation = data.data;
	            $scope.vocation.name = [];
	            for (var i = 0; i < $scope.vocation.length; i++) {
	                $scope.vocation.name.push($scope.vocation[i].name);
	            }
	            $scope.echartsInitVocation();
	        } else {
	            alert(data.msg);
	        }
	    });
	    $scope.echartsInitVocation = function () {
	        // 基于准备好的dom，初始化echarts图表
	        var myChart = echarts.init(document.getElementById("mobile_analysis_teacher_vocation"));
	        var data = $scope.vocation;
	
	        function sum(data) {
	            var s = 0;
	            for (var i = data.length - 1; i >= 0; i--) {
	                s += data[i].value;
	            }
	            return s;
	        }
	
	        var all = sum(data);
	        var newData = [];
	        for (i = 0; i < data.length; i++) {
	            newData[i] = {
	                value: data[i].value <= 1 ? data[i].value : Math.log(data[i].value),
	                name: data[i].name,
	                originalValue: data[i].value,
	                originalPercent: data[i].value / all * 100
	            };
	        }
	
	        option = {
	            tooltip: {
	                trigger: 'item',
	                formatter: function (param) {
	                    var value = param.value;
	                    var percent = param.percent;
	                    for (var i = 0; i < newData.length; i++) {
	                        if (newData[i].name == param.name) {
	                            value = newData[i].originalValue;
	                            percent = newData[i].originalPercent;
	                            break;
	                        }
	                    }
	                    return param.name + ':' + '<br>' + value + '<br>' + Math.round(percent) + '%';
	                }
	            },
	            legend: {
	                x: 'center',
	                y: 'bottom',
	                data: $scope.vocation.name
	            },
	            calculable: true,
	            series: [
	                {
	                    name: '面积模式',
	                    type: 'pie',
	                    radius: [30, 100],
	                    center: ['50%', '50%'],
	                    roseType: 'area',
	                    itemStyle: {
	                        normal: {
	                            label: {
	                                show: true,
	                                formatter: '{b}',
	                                fontSize: 12
	                            },
	                            borderWidth: 2,
	                        },
	                    },
	                    data: newData
	                }
	            ]
	        };
	        myChart.setOption(option);
	    }
	    //教师-编制类别
	    httpService.post(app.urls.teacheranalysis_selectTalent, {"fk_dictionary_school_type":fk_dictionary_school_type,"fk_unit":fk_unit}, function (data) {
	        if ("0000" === data.code) {
	            $scope.talent = data.data;
	            $scope.talent.name = [];
	            $scope.talent.value = [];
	            for (var i = 0; i < $scope.talent.length; i++) {
	                $scope.talent.name.push($scope.talent[i].name);
	                $scope.talent.value.push($scope.talent[i].value);
	            }
	            $scope.echartsInitTalent();
	        } else {
	            alert(data.msg);
	        }
	    });
	    $scope.echartsInitTalent = function () {
	        // 基于准备好的dom，初始化echarts图表
	        var myChart = echarts.init(document.getElementById("mobile_analysis_teacher_talent"));
	        data = $scope.talent;
	        sumValue = eval($scope.talent.value.join('+'));
	        objData = array2obj(data, "name");
	        optionData = getData(data);
	
	        function getArrayValue(array, key) {
	            var key = key || "value";
	            var res = [];
	            if (array) {
	                array.forEach(function (t) {
	                    res.push(t[key]);
	                });
	            }
	            return res;
	        }
	
	        function array2obj(array, key) {
	            var resObj = {};
	            for (var i = 0; i < array.length; i++) {
	                resObj[array[i][key]] = array[i];
	            }
	            return resObj;
	        }
	
	        function getData(data) {
	            var res = {
	                series: [],
	                yAxis: []
	            };
	            for (let i = 0; i < data.length; i++) {
	                res.series.push({
	                    name: '编制类别',
	                    type: 'pie',
	                    clockWise: false, //顺时加载
	                    hoverAnimation: false, //鼠标移入变大
	                    radius: [70 - i * 15 + '%', 65 - i * 15 + '%'],
	                    center: ["50%", "50%"],
	                    label: {
	                        fontSize: 12,
	                        show: false
	                    },
	                    itemStyle: {
	                        label: {
	                            fontSize: 12,
	                            show: false,
	                        },
	                        labelLine: {
	                            show: false
	                        },
	                        borderWidth: 5,
	                    },
	                    data: [{
	                        value: data[i].value,
	                        name: data[i].name
	                    }, {
	                        value: sumValue - data[i].value,
	                        name: '',
	                        itemStyle: {
	                            color: "rgba(0,0,0,0)",
	                            borderWidth: 0
	                        },
	                        tooltip: {
	                            show: false
	                        },
	                        hoverAnimation: false
	                    }]
	                });
	                res.series.push({
	                    name: '',
	                    fontSize: 12,
	                    type: 'pie',
	                    silent: true,
	                    z: 1,
	                    clockWise: false, //顺时加载
	                    hoverAnimation: false, //鼠标移入变大
	                    radius: [70 - i * 15 + '%', 65 - i * 15 + '%'],
	                    center: ["50%", "50%"],
	                    label: {
	                        show: false
	                    },
	                    itemStyle: {
	                        label: {
	                            show: false,
	                        },
	                        labelLine: {
	                            show: false
	                        },
	                        borderWidth: 5,
	                    },
	                    data: [{
	                        value: 7.5,
	                        itemStyle: {
	                            color: "#E3F0FF",
	                            borderWidth: 0
	                        },
	                        tooltip: {
	                            show: false
	                        },
	                        hoverAnimation: false
	                    }, {
	                        value: 2.5,
	                        name: '',
	                        itemStyle: {
	                            color: "rgba(0,0,0,0)",
	                            borderWidth: 0
	                        },
	                        tooltip: {
	                            show: false
	                        },
	                        hoverAnimation: false, fontSize: 12,
	                    }]
	                });
	                res.yAxis.push((data[i].value / sumValue * 100).toFixed(2) + "%");
	            }
	            return res;
	        }
	
	        option = {
	            backgroundColor: '#fff',
	            legend: {
	                show: true,
	                bottom: '-10%',
	                data: $scope.talent.name,
	                itemWidth: 14,
	                itemHeight: 14,
	                formatter: function (name) {
	                    return "{title|" + name + "}\n{value|" + (objData[name].value) + "人}"
	                },
	                textStyle: {
	                    fontSize: 12,
	                    rich: {
	                        title: {
	                            fontSize: 12,
	                            lineHeight: 12,
	                            color: "rgba(0,0,0,.45)"
	                        },
	                        value: {
	                            fontSize: 12,
	                            lineHeight: 12,
	                            color: "rgba(0,0,0,.85)"
	                        }
	                    }
	                },
	            },
	            tooltip: {
	                show: true,
	                trigger: "item",
	                fontSize: 12,
	
	            },
	            color: ['#FF8700', '#ffc300', '#00e473', '#009DFF'],
	            grid: {
	                top: '15%',
	                bottom: '54%',
	                left: "50%",
	                containLabel: false
	            },
	            yAxis: [{
	                type: 'category',
	                inverse: true,
	                axisLine: {
	                    show: false
	                },
	                axisTick: {
	                    show: false
	                },
	                axisLabel: {
	                    interval: 0,
	                    inside: true,
	                    textStyle: {
	                        color: "#000",
	                        fontSize: 10,
	                    },
	                    show: true
	                },
	                data: optionData.yAxis
	            }],
	            xAxis: [{
	                show: false
	            }],
	            series: optionData.series
	        };
	        myChart.setOption(option);
	    }
	    //教师-学历情况
	    httpService.post(app.urls.teacheranalysis_selectDegree, {"fk_dictionary_school_type":fk_dictionary_school_type,"fk_unit":fk_unit}, function (data) {
	        if ("0000" === data.code) {
	            $scope.degree = data.data;
	            $scope.echartsInitDegree();
	        } else {
	            alert(data.msg);
	        }
	    });
	    $scope.echartsInitDegree = function () {
	        // 基于准备好的dom，初始化echarts图表
	        var myChart = echarts.init(document.getElementById("mobile_analysis_teacher_degree"));
	        option = {
	            tooltip: {
	                trigger: 'item',
	                formatter: "{a} <br/>{b} : {c} ({d}%)"
	            },
	            color: ['#8fc31f', '#f35833', '#00ccff', '#ffcc00'],
	            series: [
	                {
	                    name: '学历情况',
	                    type: 'pie',
	                    radius: '55%',
	                    center: ["50%", "50%"],
	                    radius: ["40%", "60%"],
	                    data: $scope.degree,
	                    itemStyle: {
	                        emphasis: {
	                            shadowBlur: 10,
	                            shadowOffsetX: 0,
	                            shadowColor: 'rgba(0, 0, 0, 0.5)'
	                        }
	                    },
	                    itemStyle: {
	                        normal: {
	                            label: {
	                                show: true,
	                                //	                            position:'inside',
	                                formatter: '{b}:\n{c} ({d}%)',
	                                fontSize: 12
	                            },
	                            borderColor: '#ffffff',
	                            borderWidth: 2,
	                        },
	                        labelLine: {
	                            show: true,
	                            length: 10,
	                            length2: 30,
	                        }
	                    }
	                }
	            ]
	        };
	        myChart.setOption(option);
	    }
	    //教师-学位情况
	    httpService.post(app.urls.teacheranalysis_selectQualifications, {"fk_dictionary_school_type":fk_dictionary_school_type,"fk_unit":fk_unit}, function (data) {
	        if ("0000" === data.code) {
	            $scope.gualifc = data.data;
	            $scope.echartsInitGualifc();
	        } else {
	            alert(data.msg);
	        }
	    });
	    $scope.echartsInitGualifc = function () {
	        // 基于准备好的dom，初始化echarts图表
	        var myChart = echarts.init(document.getElementById("mobile_analysis_teacher_qualifications"));
	        option = {
	            tooltip: {
	                trigger: 'item',
	                formatter: "{a} <br/>{b} : {c} ({d}%)"
	            },
	            color: ['#b82af3', '#f38c2a', '#f32aed', '#cf6767'],
	            series: [
	                {
	                    name: '学位情况',
	                    type: 'pie',
	                    radius: '55%',
	                    center: ["50%", "50%"],
	                    radius: ["50", "60%"],
	                    data: $scope.gualifc,
	                    itemStyle: {
	                        emphasis: {
	                            shadowBlur: 10,
	                            shadowOffsetX: 0,
	                            shadowColor: 'rgba(0, 0, 0, 0.5)'
	                        }
	                    },
	                    itemStyle: {
	                        normal: {
	                            label: {
	                                show: true,
	                                formatter: '{b}:{c}人',
	                                fontSize: 12
	                            },
	                        },
	                        labelLine: {
	                            show: true,
	                            length: 10,
	                            length2: 30,
	                        }
	                    }
	                }
	            ]
	        };
	        myChart.setOption(option);
	    }
	    //教师-编制类别
	    httpService.post(app.urls.teacheranalysis_selectFormation, {"fk_dictionary_school_type":fk_dictionary_school_type,"fk_unit":fk_unit}, function (data) {
	        if ("0000" === data.code) {
	            $scope.formation = data.data;
	            $scope.echartsInitormation();
	        } else {
	            alert(data.msg);
	        }
	    });
	    $scope.echartsInitormation = function () {
	        // 基于准备好的dom，初始化echarts图表
	        var myChart = echarts.init(document.getElementById("mobile_analysis_teacher_formation"));
	        var data = $scope.formation;
	        var xdata = [];
	        var ydata = [];
	        var sundata = '';
	        for (var i = 0; i < data.length; i++) {
	            xdata.push(data[i].name);
	            ydata.push(data[i].value);
	        }
	
	        function sum(arr) {
	            return eval(arr.join("+"));
	        };
	        sundata = sum(ydata);
	        option = {
	            title: {
	                text: sundata + '人',
	                x: 'center',
	                y: 'center',
	                textStyle: {
	                    fontWeight: 'normal',
	                    fontSize: 22
	                }
	            },
	            tooltip: {
	                show: true,
	                trigger: 'item',
	                formatter: "{b}: {c} ({d}%)"
	            },
	
	            legend: {
	                orient: 'horizontal',
	                top: '0%',
	                data: xdata
	            },
	            series: [{
	                type: 'pie',
	                selectedMode: 'single',
	                radius: ['40%', '60%'],
	                color: ['#33836b', '#333583', '#833333'],
	
	                label: {
	                    normal: {
	                        position: 'inner',
	                        formatter: '{c}',
	
	                        textStyle: {
	                            color: '#fff',
	                            fontWeight: 'bold',
	                            fontSize: 12
	                        }
	                    }
	                },
	                labelLine: {
	                    normal: {
	                        show: false
	                    }
	                },
	                data: data
	            }]
	        };
	        myChart.setOption(option);
	    }
	}
	$scope.find();
}}});